package com.yonyou.lxp.xutils3test.ui.db;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.bigkoo.pickerview.TimePickerView;
import com.yonyou.lxp.xutils3test.R;
import com.yonyou.lxp.xutils3test.ui.BaseFragment;
import com.yonyou.lxp.xutils3test.views.dialog.TimeView;

import org.xutils.common.util.DensityUtil;
import org.xutils.common.util.LogUtil;
import org.xutils.image.ImageOptions;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.text.SimpleDateFormat;
import java.util.Date;


@ContentView(R.layout.fragment_db)
public class DbFragment extends BaseFragment {

    @ViewInject(R.id.img_gif1)
    private ImageView img_gif1;

    @ViewInject(R.id.img_gif2)
    private ImageView img_gif2;

    @ViewInject(R.id.timeView)
    private TimeView timeView;

    TimePickerView pvTime;
    public static DbFragment newInstance(String param1, String param2) {
        DbFragment fragment = new DbFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }


    @Event(value = {R.id.btn_db})
    private  void onClick(View view){
        switch (view.getId()){
            case R.id.btn_db:
                Toast.makeText(mContext,"数据库",Toast.LENGTH_SHORT).show();
                break;
        }

    }
    ImageOptions imageOptions;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        pvTime=new TimePickerView(mContext, TimePickerView.Type.YEAR_MONTH_DAY);
        pvTime.setTime(new Date());
        pvTime.setTitle("123123123123");
        pvTime.setCyclic(false);
        pvTime.setCancelable(true);
        //时间选择后回调
        pvTime.setOnTimeSelectListener(new TimePickerView.OnTimeSelectListener() {

            @Override
            public void onTimeSelect(Date date) {
//                tvTime.setText(getTime(date));

                LogUtil.e(getTime(date));
            }
        });


//        timeView.setTime(new Date());

        pvTime.show();

//        //弹出时间选择器
//        tvTime.setOnClickListener(new View.OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                pvTime.show();
//            }
//        });



        imageOptions = new ImageOptions.Builder().setIgnoreGif(false).build();
        x.image().bind(img_gif1,"assets://gif/loading.gif",imageOptions);
        x.image().bind(img_gif2,"assets://gif/aaa.gif",imageOptions);
    }

    public static String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return format.format(date);
    }
}
